package cn.sjxy.service;

import cn.sjxy.baseLib.SjuException;
import cn.sjxy.baseLib.SjuSecurity;
import cn.sjxy.mapper.Mp_Admin;
import cn.sjxy.model.Md_Admin;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Sv_Admin {
    @Autowired
    private Mp_Admin mp_admin;

    /**
     * 检查账号是否可以登录
     *
     * @param adminCode
     * @param password
     * @return
     */
    public Md_Admin checkLogin(String adminCode, String password) throws Exception {
        QueryWrapper<Md_Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("adminCode", adminCode);
        wrapper.eq("password", SjuSecurity.toMD5(password));

        Md_Admin entry = mp_admin.selectOne(wrapper);
        if(entry == null)
            SjuException.appEx("账号或密码错误");

        return entry;
    }
}
